package com.origin.oss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.origin.oss.entity.FileInfo;
import com.origin.oss.mapper.FileInfoMapper;
import com.origin.oss.service.FileInfoService;
import org.springframework.stereotype.Service;

/**
 * @author yezh
 * @date 2024/2/5 13:29
 */
@Service
public class FileInfoServiceImpl implements FileInfoService {

    private final FileInfoMapper fileInfoMapper;

    public FileInfoServiceImpl(FileInfoMapper fileInfoMapper) {
        this.fileInfoMapper = fileInfoMapper;
    }

    @Override
    public void insert(FileInfo fileInfo) {
        fileInfoMapper.insert(fileInfo);
    }

    @Override
    public boolean existByIdentifier(String identifier) {
        return false;
    }

    @Override
    public String getFileIdByIdentifier(String identifier) {
        FileInfo fileInfo = fileInfoMapper.selectOne(new LambdaQueryWrapper<FileInfo>().eq(FileInfo::getIdentifier, identifier).select(FileInfo::getFileId));
        return fileInfo == null ? null : fileInfo.getFileId();
    }

    @Override
    public FileInfo getByIdentifier(String identifier) {
        return fileInfoMapper.selectOne(new LambdaQueryWrapper<FileInfo>().eq(FileInfo::getIdentifier, identifier));
    }

    @Override
    public FileInfo getByFileId(String fileId) {
        return fileInfoMapper.selectOne(new LambdaQueryWrapper<FileInfo>().eq(FileInfo::getFileId, fileId));

    }

}
